<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue路由开发-参数传递</title>
</head>

<body>
    <div id="app">
        <h1>{{msg}}</h1>
        <router-link to="/t1?id=1&name=张三" tag="button">跳转到t1组件</router-link>
        <router-link to="/t2/2/李四" tag="button">跳转到t2组件</router-link>
        <!-- 路由匹配到的组件会被渲染在这里 -->
        <router-view></router-view>
    </div>
</body>
<!-- 模板1 -->
<template id="t1">
    <div>
        <h1>组件1</h1>
        <!-- 获取路由参数 -->
        <p>id:{{id}}</p>
        <p>name:{{name}}</p>
    </div>
</template>
<!-- 模板2 -->
<template id="t2">
    <div>
        <h1>组件2</h1>
        <!-- 获取路由参数 -->
        <p>id:{{id}}</p>
        <p>name:{{name}}</p>
    </div>
</template>

</html>
<script type="module">
    import { } from './js/vue.js'
    import { } from './js/vue-router.js'

    const t1 = {
        template: '#t1',
        data() {
            return {
                id: this.$route.query.id,
                name: this.$route.query.name
            }
        }
    }
    const t2 = {
        template: '#t2',
        data() {
            return {
                id: this.$route.params.id,
                name: this.$route.params.name
            }
        }
    }

    //创建路由规则
    const routes = [
        { path: '/t1', component: t1 },
        { path: '/t2/:id/:name', component: t2 },
    ]

    //创建路由实例
    const router = new VueRouter({
        routes
    })

    const app = new Vue({
        el: '#app',
        data: {
            msg: 'vue路由开发-参数传递'
        },
        methods: {

        },
        router

    })
</script>